const Mock = require('mockjs')

const data = Mock.mock({
  'items|30': [{
    appId: '@id',
    appName: '@name',
    appCode: '@integer(10, 300)',
    clientSecret: '@integer(10, 50)',
    clientId: '@integer(10, 30000)',
    loginCallbackAddress: '@integer(10, 30)',
    logoutCallbackAddress: '@integer(10, 30)',
    appDomainName: '@name',
    'authMethod|1': ['账号密码', '邮箱验证', '手机短信', '滑块验证码'],
    createTime: '@date(yyyy-MM-dd HH:mm:ss)'
  }]
})
module.exports = [
  {
    url: '/singlePointAuthList/page',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  {
    url: '/singlePointAuthList/add',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  },
  {
    url: '/singlePointAuthList/detail',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { appId } = config.query
      for (const item of items) {
        if (item.appId === appId) {
          return {
            code: '00000',
            data: item
          }
        }
      }
    }
  },
  {
    url: '/singlePointAuthList/edit',
    type: 'post',
    response: (config) => {
      const { items } = data
      const { appId } = config.body
      for (const item of items) {
        if (item.appId === appId) {
          return {
            code: '00000',
            data: 'success'
          }
        }
      }
    }
  },
  {
    url: '/singlePointAuthList/delete',
    type: 'post',
    response: (config) => {
      const { items } = data
      const { appId } = config.body
      for (const item of items) {
        if (item.appId === appId) {
          return {
            code: '00000',
            data: 'success'
          }
        }
      }
    }
  }
]
